<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){

        $category=M('category');
        $catelist=$category->where('pid=0')->select();            
        foreach($catelist as $k=>$v)
        {            
            $catelist[$k]['child']=fenlei($v['cid']);         
        }
        $this->assign("catelist",$catelist);
        $best=M('goods');        
        $bestlist=$best->where("is_best='yes'  and recycle='no'")->select();
        $this->assign("bestlist",$bestlist);
        $this->display();
    }
    public function goods(){
    $gid=I('get.gid',0);
    $goods=M('goods');
    $goodsrow=$goods->where("gid=$gid")->find();
    $cid=$goodsrow['cid'];
    $types=D("Category")->getPidList($cid);
    $attr=D("GoodsAttr")->getData($cid,$gid);
    $this->assign("types",$types);
    $this->assign("goodsrow",$goodsrow);
    $this->assign("attr",$attr);
    $this->display();
    }
    public function find(){
    $cid=I('get.cid',0);
    $cname=M('category')->where("cid=$cid")->getField("cname");
    $gdata=D('Goods')->getByFilter(
            'gid,gname,price,thumb',
            array('cid'=>$cid)
            );
    $this->assign('gdata',$gdata);
    $this->assign('cname',$cname);
    $this->display();
    }
}